package com.jiazhong.shixi.bean.controller;

import com.jiazhong.shixi.bean.bean.Book;
import com.jiazhong.shixi.bean.mapper.BookMapper;
import com.jiazhong.shixi.bean.util.JsonResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/book")
public class BookController {
    @Resource
    private BookMapper bookMapper;

    @RequestMapping("/fresh_book")
    public JsonResult findByFreshBook(){
        List<Book> list = bookMapper.findByFreshBook();
        JsonResult result = new JsonResult(true,200,list,"");
        return result;
    }
    @RequestMapping("/fresh_book_more")
    public JsonResult findByFreshBookMore(){
        List<Book> list = bookMapper.findByFreshBookMore();
        JsonResult result = new JsonResult(true,200,list,"");
        return result;
    }
    @RequestMapping("/lower_book")
    public JsonResult findByLowerBook(){
        List<Book> list = bookMapper.findByLowerBook();
        JsonResult result = new JsonResult(true,200,list,"");
        return result;
    }
    @RequestMapping("/lower_book_more")
    public JsonResult findByLowerBookMore() {
        List<Book> list = bookMapper.findByLowerBookMore();
        JsonResult result = new JsonResult(true, 200, list, "");
        return result;
    }
    @RequestMapping("/find_book_like")
    public JsonResult findByLikeName(String name){
        List<Book> list = bookMapper.fimdByLikeName("%" + name + "%");
        JsonResult result = new JsonResult(true, 200, list, "");
        return result;
    }
}
